package com.zoespeer.food_delivery_comment_api.common;

import lombok.Data;

@Data
public class ApiResponse<T> {
    private int code;
    private String message;
    private T data;

    // 新增：判断是否成功（code=200即为成功）
    public boolean isSuccess() {
        return this.code == 200;
    }
    // 新增：仅传数据，使用默认成功消息
    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 200;
        response.message = "success"; // 默认成功消息
        response.data = data;
        return response;
    }
    public static <T> ApiResponse<T> success(T data, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 200;
        response.message = message;
        response.data = data;
        return response;
    }

    public static <T> ApiResponse<T> success(String message) {
        return success(null, message);
    }

    public static <T> ApiResponse<T> error(String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 500;
        response.message = message;
        response.data = null;
        return response;
    }

    public static <T> ApiResponse<T> paramError(String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.code = 400;
        response.message = message;
        response.data = null;
        return response;
    }
}